package cn.com.xy.sms.sdk.ui.popu.util;

import android.content.Context;
import android.content.SharedPreferences;
import cn.com.xy.sms.sdk.constant.Constant;

/**
 * 文件管理类
 */
public class SPUtil {

    private static SharedPreferences mSharedPreferences;
    private static final String SPNAME = "train_button_flag";
    private static final String TAG = "SPUtil";

    private SPUtil() {
    }

    public static void init() {
        if (mSharedPreferences == null) {
            synchronized (SPUtil.class) {
                if (mSharedPreferences == null) {
                    mSharedPreferences = Constant.context.getSharedPreferences(SPNAME, Context.MODE_PRIVATE);
                }
            }
        }
    }

    public static void putString(String key, String value) {
        try {
            SharedPreferences.Editor editor = mSharedPreferences.edit();
            editor.putString(key, value);
            editor.commit();
        } catch (Throwable ex) {
            SmartSmsSdkUtil.smartSdkExceptionLog(TAG, ex);
        }
    }

    public static String getString(String key) {
        String result = "";
        try {
            result = mSharedPreferences.getString(key, "");
        } catch (Throwable ex) {
            SmartSmsSdkUtil.smartSdkExceptionLog(TAG, ex);
        }
        return result;
    }

}
